package cn.vendpay.com.mapper;


import cn.vendcommon.com.entity.VideoItem;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface VideoMapper {

    @Select("insert into video_item (user_id, machine_id, url, process_status, create_time) values (#{userId}, #{machineId}, #{url}, #{processStatus}, #{createTime})")
    void insertVideo(VideoItem videoItem);

    /**
     * 根据状态获取最早创建的前 limitNum 条 VideoItem
     * @param status 视频状态
     * @param limitNum 限制数量
     * @return VideoItem 列表
     */
    List<VideoItem> getVideoItemsByStatusLimitNum(@Param("status") int status, @Param("limitNum") int limitNum);


    /**
     * 批量更新视频状态
     * @param videoItems 要更新的视频列表
     * @return 受影响的行数
     */
    int updateStatus(List<VideoItem> videoItems);

    List<VideoItem> getVideoItemsByStatus(int status);

    @Select("select url from video_item where id = #{videoId}")
    String getUrlByVideoId(int videoId);

    /**
     * 根据视频ID删除视频记录
     * @param videoId 视频ID
     */
    @Select("delete from video_item where id = #{videoId}")
    void deleteByVideoId(int videoId);

    /**
     * 根据视频ID获取视频状态
     * @param videoId 视频ID
     * @return 视频状态
     */
    @Select("select process_status from video_item where id = #{videoId}")
    Integer getStatusByVideoId(int videoId);

    @Update("UPDATE video_item SET is_deleted = 1 WHERE id = #{videoId}")
    int markDeleted(@Param("videoId") int videoId);

    @Select("SELECT url FROM video_item WHERE is_deleted = 1 LIMIT #{batchSize}")
    List<String> getDeletedVideos(@Param("batchSize") int batchSize);

    @Delete("DELETE FROM video_item WHERE url = #{url} AND is_deleted = 1")
    int deleteByUrl(@Param("url") String url);
}
